/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package session.stateless;

import javax.ejb.EJB;
import javax.ejb.Stateless;
import persistence.entity.Account;
import persistence.entity.Biller;
import persistence.entity.Customer;

/**
 *
 * @author Dotke
 */
@Stateless
public class AccountHelper implements AccountHelperRemote, AccountHelperLocal {

    @EJB
    private CustomerFacadeRemote customerFacade;
    @EJB
    private BillerFacadeRemote billerFacade;
    @EJB
    private AccountFacadeRemote accountFacade;

    @Override
    public void createCustomerAccount(int custID) {

        createAccount('C', customerFacade.find(custID), null);

    }

    @Override
    public void createBillerAccount(int billerID) {
        createAccount('B', null, billerFacade.find(billerID));
    }

    private void createAccount(char type, Customer cust, Biller bill) {
        Account acc = new Account();

        acc.setAccountType(type);
        acc.setAccountBalance(0);
        acc.setAccountCustomerId(cust);
        acc.setAccountBillerId(bill);
        acc.setIsdisabled(Boolean.FALSE.toString());
        System.out.println("Testing");
        try {
            accountFacade.create(acc);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }

    }

    @Override
    public void disableAccount(int accountId) {

        Account acc = accountFacade.find(accountId);
        acc.setIsdisabled(Boolean.TRUE.toString());
        accountFacade.edit(acc);

    }

    @Override
    public void disableAccountLocal(int accountID) {
        Account acc = accountFacade.find(accountID);
        acc.setIsdisabled(Boolean.TRUE.toString());
        accountFacade.edit(acc);
    }
}
